﻿using UnityEngine;
using System.Collections;

public class NavMeshAgentObj : MonoBehaviour
{
    public Vector3 Point { get; private set; }

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;//

            if (Physics.Raycast(ray, out hit))//函数是对射线碰撞的检测，这个out是什么意思？
            {
                Point = hit.point;//得到碰撞点的坐标
                Debug.Log(Point);//输出一下
                Debug.Log("I'm looking at " + hit.transform.name);//输出碰到的物体名字
                if (hit.transform.name == "Plane") {
                    NavMeshAgent agent = this.GetComponent<NavMeshAgent>();
                    agent.SetDestination(Point);
                }
            }
        }
    }
}
